<template>
  <el-row :gutter="24">
    <el-col :span="6">
      <el-form-item label="提单号" prop="blno">
        <el-input v-model="data.blno" placeholder="请输入"> </el-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="BOOKING">
        <el-input v-model="data.bookingNo" placeholder="请输入"> </el-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="合约号">
        <el-input v-model="data.contractNumber" placeholder="请输入"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="船代">
        <!-- <selectDown
          v-model:modelData="data.shipingAgent"
          placeholder="请输入后搜索"
          urlType="crcontactcompany"
          :urlQueryData="'船司'"
          :labelSpaceBetween="true"
          :remoteShowSuffix="false"
          @getOption="setShipingAgentCode"
        >
        </selectDown> -->
        <el-autocomplete
          v-model="data.shipingAgent"
          :fetch-suggestions="queryShipingAgent"
          placeholder="请输入选择"
          style="width: 100%"
          value-key="label"
          :clearable="true"
        ></el-autocomplete>
      </el-form-item>
    </el-col>
  </el-row>
  <el-row :gutter="24">
    <el-col :span="6">
      <el-form-item label="船名" prop="vessel">
        <selectDown
          v-model:modelData="data.vessel"
          placeholder="请输入后搜索"
          urlType="CsShip"
          @getOption="setVesselId"
          @handleChange="cleaerVess"
          :remoteShowSuffix="false"
        >
        </selectDown>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="航次" prop="voyage">
        <!-- <selectDown
          v-model:modelData="data.voyage"
          placeholder="请输入后搜索"
          urlType="CsVoyage"
          :remoteShowSuffix="false"
        >
        </selectDown> -->
        <el-autocomplete
          v-model="data.voyage"
          :fetch-suggestions="queryVoyage"
          placeholder="请输入选择"
          style="width: 100%"
          value-key="label"
          :clearable="true"
        ></el-autocomplete>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="靠泊码头">
        <el-input v-model="data.berthWharf" placeholder="请输入"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="进港代码">
        <el-input v-model="data.enterPortCode" placeholder="请输入"></el-input>
      </el-form-item>
    </el-col>
  </el-row>
  <el-row :gutter="24">
    <el-col :span="6">
      <el-form-item label="开航日期" prop="atd">
        <el-date-picker
          v-model="data.atd"
          type="date"
          placeholder="请选择"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="截港时间">
        <el-date-picker
          v-model="data.deadlinePortTime"
          type="datetime"
          placeholder="请选择"
          format="YYYY-MM-DD HH:mm"
          time-format="HH:mm"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="截关时间">
        <el-date-picker
          v-model="data.deadlineCustomsTime"
          type="datetime"
          placeholder="请选择"
          format="YYYY-MM-DD HH:mm"
          time-format="HH:mm"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="截单时间">
        <el-date-picker
          v-model="data.deadlineOrderTime"
          type="datetime"
          placeholder="请选择"
          format="YYYY-MM-DD HH:mm"
          time-format="HH:mm"
          value-format="YYYY-MM-DD HH:mm"
        />
      </el-form-item>
    </el-col>
  </el-row>
</template>

<script setup>
import { computed, defineComponent, nextTick, reactive, ref } from 'vue'
import AppSearchForm from '@/components/AppSearchForm.vue'
import AppPageTable, { useTableOption } from '@/components/AppPageTable2'
import dayjs from 'dayjs'
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
import { useStore, Store } from 'vuex'
import request from '@/public/request'
import selectDown from '../newBusiness/selectDownNew.vue'
import vueBus from '@/utils/vueBus'
import docSelects from './../components/docSelects.vue'
import docDetailFillShipperNew from './docDetailFillShipperNew.vue'
import { validateOnlyNumberTwo, validateNumber } from '@/utils/validate.js'

//判断当前打开的是否是业务列表
const props = defineProps({
  detailData: {
    type: Object,
    defalut: () => {}
  },
  //初始化option
  initOption: {
    type: Object,
    default: () => {}
  }
})

// 弹框的form表单
const addFormRef = ref(null)
const BLDialog = ref(null)

const state = reactive({
  show: false,
  showCheck: false,
  secondeShow: false,
  timeout: null
})

async function queryVoyage(val, cb) {
  if (state.timeout) {
    clearTimeout(state.timeout)
  }
  // state.timeout = setTimeout(async () => {
  let res = await request.get('/api/csvoyage/querypage', {
    PageIndex: 1,
    PageSize: 50,
    VoyageName: val == 'null' ? '' : val,
    ShipId: props.detailData.shipId
  })
  if (res) {
    let options = res.content.map((item) => {
      return {
        id: item.id,
        value: item.voyageName,
        label: item.voyageName,
        selectLabel: item.voyageName
      }
    })
    cb(options)
  } else {
    console.error(error)
    cb([])
  }
  // }, 50)
}
// 船代
async function queryShipingAgent(val, cb) {
  if (state.timeout) {
    clearTimeout(state.timeout)
  }
  // state.timeout = setTimeout(async () => {
  let res = await request.get('/api/crcontactcompany/query', {
    PageIndex: 1,
    PageSize: 50,
    code: val == 'null' ? '' : val,
    businessCategory: '船司'
  })
  if (res) {
    let options = res.content.map((item) => {
      return {
        id: item.id,
        value: item.comNameCn,
        label: item.comNameCn,
        selectLabel: item.comNameCn,
        leftName: item.comNameCn,
        rigthName: item.comCode
      }
    })
    cb(options)
  } else {
    console.error(error)
    cb([])
  }
  // }, 50)
}

function setVesselId(item) {
  console.log(item, 'item')
  props.detailData.shipId = item.id
}

function cleaerVess() {
  props.detailData.shipId = ''
}

// 保存船代的code
function setShipingAgentCode(item) {
  props.data.shipingAgentCode = item.rigthName
}

const data = computed({
  get() {
    return props.detailData
  },
  set(value) {
    emits('update:detailData', value)
  }
})

const emits = defineEmits(['update:detailData'])

const Router = useRouter()
const Route = useRoute()
const store = useStore()
</script>

<style lang="scss" scoped>
.container {
  :deep(.el-form-item) {
    margin: 0;
  }

  :deep(.el-row) {
    margin-bottom: 8px;
  }

  .middle-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    background: #f5f8f7;
    padding: 2px 8px;

    .label {
      // border-left: 2px solid #5d9df5;
      // margin-left: 12px;
      // padding-left: 4px;
      // color: #000000;
      // font-family: PingFang SC;
      // font-weight: bold;
      // font-size: 14px;
      // letter-spacing: 0px;
      color: #000000d8;
      font-family: PingFang SC;
      font-weight: normal;
      font-size: 12px;
      line-height: 20px;
      letter-spacing: 0px;
    }
    .tempalte-text {
      color: #5a9cf8;
      font-family: PingFang SC;
      font-weight: normal;
      font-size: 12px;
      letter-spacing: 0px;
      margin-left: 12px;
      cursor: pointer;
    }

    .fold,
    .expand {
      color: #5e9ef5;
      cursor: pointer;
    }

    .btn {
      cursor: pointer;
      color: #0063b9;
      margin: 0 16px 0 8px;
    }

    :deep(.el-checkbox) {
      margin-left: 16px;
    }
  }
  .no-data {
    width: 100%;
    margin-bottom: 16px;
    color: #000000;
    opacity: 0.4;

    font-family: PingFang SC;
    font-weight: normal;
    font-size: 12px;
    line-height: 1.5;
    letter-spacing: 0px;
    text-align: center;
  }

  .message-input-container:first-child {
    // border-top: none;
    // padding-top: 12px;
  }

  .message-input-container {
    width: 100%;
    // padding: 8px 12px 0px;
    // border-top: 8px solid #f8f8f8;
    :deep(.el-table .el-table__header-wrapper th) {
      color: #000000d8;
      font-family: PingFang SC;
      font-weight: 400;
      font-size: 12px;
      letter-spacing: 0px;
    }

    .expand-icon {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 8px;
      span {
        color: #5a9cf8;
        font-family: PingFang SC;
        font-weight: normal;
        font-size: 12px;
        line-height: 20px;
        letter-spacing: 0px;
        margin-right: 4px;
      }
    }
    .rotate {
      transform: rotate(-180deg);
    }
    .collapse {
      transition: all 0.5s ease;
    }
    .no-bottom {
      margin-bottom: 0px;
    }
  }

  :deep(.el-input-group__append, .el-input-group__prepend) {
    padding: 0 8.5px;
    background-color: #f8f8f8;
  }

  .no-border-top {
    border-top: none;
  }

  .middle-box:not(.special) {
    justify-content: space-between;
  }

  .flex-column {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    text-align: right;

    .first-title {
      color: #000000d8;
      font-family: PingFang SC;
      font-weight: 400;
      font-size: 12px;
      letter-spacing: 0px;
      cursor: pointer;
    }

    .sencond-title {
      color: #000000;
      opacity: 0.4;
      font-family: PingFang SC;
      font-weight: 400;
      font-size: 12px;
      letter-spacing: 0px;
      cursor: pointer;
    }
  }

  .responsiveLayout {
    width: 100%;
    display: flex;
  }

  ::v-deep .el-input-number__decrease {
    background-color: #fff;
    border-right: none;
  }
  ::v-deep .el-input-number__increase {
    background-color: #fff;
    border-left: none;
  }

  .choice {
    color: #5a9cf8;
    font-family: PingFang SC;
    font-weight: 400;
    font-size: 12px;
    line-height: 20px;
    letter-spacing: 0px;
    cursor: pointer;
  }

  .flex-item-label {
    color: rgba(0, 0, 0, 0.8470588235);
    font-family: PingFang SC;
    font-weight: 400;
    font-size: 12px;
    letter-spacing: 0px;
    line-height: 24px;
    width: 80px;
    text-align: right;
    margin-right: 8px;
    flex: 0 0 80px;
  }

  .flex-container {
    display: flex;
    justify-content: flex-start;
  }

  .box-item {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .box-container {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .delete-icon {
    position: absolute;
    top: -5px;
    right: -4px;
    z-index: 100;
    color: #c5c5c5;
    cursor: pointer;
  }

  .box-item-fill {
    margin-right: 8px;
    display: flex;
    align-items: center;
    position: relative;
  }

  .addUseBoxInfo {
    color: #6ba5f6;
    cursor: pointer;
    width: 50px;
    height: 24px;
    display: flex;
    align-items: center;
    margin: 12px 0 10px 0px;
    .addFont {
      margin-left: 3px;
      line-height: 21px;
    }
  }

  .box-contaienr-input {
    display: flex;
    align-items: center;
    width: calc(100% - 48px);
  }

  .add-use-box-info-new {
    color: #6ba5f6;
    cursor: pointer;
    // width: 50px;
    height: 24px;
    display: flex;
    align-items: center;
    margin-left: 4px;
    // flex: 0 0 50px;
    .addFont {
      margin-left: 3px;
      line-height: 24px;
    }
  }
}
.input-number-style {
  :deep(.el-input-number.is-without-controls .el-input__wrapper) {
    padding: 2px 8px;
  }
  :deep(.el-input-number .el-input__inner) {
    text-align: left;
  }
}

.table-header::before {
  content: '*';
  color: #f56c6c;
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0px;
  position: absolute;
  left: 11px;
}

.table-header-other::before {
  content: '*';
  color: #f56c6c;
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0px;
  position: absolute;
  left: 22px;
}

:deep(.el-form-item--small .el-form-item__label) {
  color: #000000d8;
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 12px;
  line-height: 24px;
  letter-spacing: 0px;
}

:deep(.el-input-number--small) {
  width: 100%;
}

:deep(.el-form-item.is-error .el-checkbox__input .el-checkbox__inner) {
  border-color: #f56c6c;
}
:deep(.el-checkbox.el-checkbox--small) {
  margin-right: 12px;
}
</style>
